var app = getApp();
const Zan = require('../../../dist/index');

Page(Object.assign(Zan.TopTips, {

	data: {
		reShow: true,
		user: {},
		genderArray: ['未设置', '男', '女'],
		genderIndex: 0
	},

	onLoad: function () {
		this.userinfo();
	},

	onShow: function () {

	},

	reAvatar: function () {
		var that = this;

		wx.chooseImage({
			success: function (res) {
				var tempFilePaths = res.tempFilePaths
				console.log(tempFilePaths);
				app.battery.uploadAvatar(tempFilePaths[0], {}).then(function (d) {
					if (d) {
						var user = that.data.user;
						user.avatar = d;
						that.setData({
							user: user
						});
					} else {
						that.showZanTopTips('上传失败，请重试', {type: 'error'});
					}
				}).catch(function (e) {
					console.log(e);
					that.showZanTopTips(e.errMsg, {type: 'error'});
				});
			}
		})
	},

	userinfo: function () {
		var that = this;

		// get userinfo
		app.battery.findOne('member/detail', app.data.member.id).then(function (r) {
			let gender = '未设置';
			if (r.gender == 1) {
				gender = '男';
			} else if (r.gender == 2) {
				gender = '女';
			}
			that.setData({
				user: {
					balance: r.walletMoney,
					avatar: r.avatar,
					nickName: r.name,
					mobile: r.mobile,
					bindWebchat: r.bindWebchat,
					checkIdcard: r.checkIdcard,
					checkMobile: r.checkMobile,
					foregiftMoney: r.foregiftMoney,
					networkActive: r.networkActive,
					payForegift: r.payForegift,
					payWallet: r.payWallet,
					gender: gender,
					birthday: r.birthday
				},
				genderIndex: r.gender
			});
		}).catch(function (e) {
			that.showZanTopTips(e.message, {type: 'error'});
		});
	},

	toCheck: function () {
		wx.navigateTo({
			url: '/pages/user/idcard/idcard'
		})
	}
}));